package com.benny_driving.util;

import java.text.DecimalFormat;
import java.util.Calendar;

public class FormatUtil {
	public static String getTimeFormatNow() {
		return getTimeFormat(System.currentTimeMillis());
	}

	public static String getTimeFormat(long millis) {
		Calendar c = Calendar.getInstance();
		c.setTimeInMillis(millis);
		String time = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1)
				+ "-" + c.get(Calendar.DAY_OF_MONTH) + " "
				+ c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE)
				+ ":" + c.get(Calendar.SECOND);
		return time;
	}

	public static double gps2m(double lat_a, double lng_a, double lat_b,
			double lng_b) {
		double earth_radius = 6378137.0;
		double radLat1 = (lat_a * Math.PI / 180.0);
		double radLat2 = (lat_b * Math.PI / 180.0);
		double a = radLat1 - radLat2;
		double b = (lng_a - lng_b) * Math.PI / 180.0;
		double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
				+ Math.cos(radLat1) * Math.cos(radLat2)
				* Math.pow(Math.sin(b / 2), 2)));
		s = s * earth_radius;
		s = Math.round(s * 10000) / 10000;
		return s;
	}

	public static double getFormatDouble(int decimalPoint, double params) {
		if (decimalPoint < 1) {
			return Math.floor(params);
		}
		StringBuffer sb = new StringBuffer(".");
		for (int i = 0; i < decimalPoint; i++) {
			sb.append("#");
		}
		DecimalFormat df = new DecimalFormat(sb.toString());
		return Double.parseDouble(df.format(params));
	}
}
